//
//  GSCommonFindPassResetView.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/30.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonFindPassResetView.h"

@interface GSCommonFindPassResetView ()

@property (nonatomic, strong) UITextField *passwordNewTF;

/**
 *
 */
@property (nonatomic, strong) UITextField *rePasswordNewTF;

@end

@implementation GSCommonFindPassResetView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupSubviews];
        //
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passwordTextFeildDidChangedNotification) name:UITextFieldTextDidChangeNotification object:self.passwordNewTF];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passwordTextFeildDidChangedNotification) name:UITextFieldTextDidChangeNotification object:self.rePasswordNewTF];
    }
    return self;
}

- (void)setupSubviews {
    NSDictionary *placehodlerDic = @{NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightRegular],NSForegroundColorAttributeName:GSLOGINRGBRGBHEX(0xD9D9D9)};
    self.passwordNewTF = [self passwordTextFeild];
    self.passwordNewTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:GSLoginLocalized(@"Input new password") attributes:placehodlerDic];
    [self addSubview:self.passwordNewTF];
    
    //
    self.rePasswordNewTF = [self passwordTextFeild];
    self.rePasswordNewTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:GSLoginLocalized(@"Confirm new password") attributes:placehodlerDic];
    [self addSubview:self.rePasswordNewTF];
    //
    [self.passwordNewTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20.0);
        make.top.mas_equalTo(self);
        make.width.mas_equalTo(self).offset(-40.0);
        make.height.mas_equalTo(self).multipliedBy(.5);
    }];
    [self.rePasswordNewTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.right.mas_equalTo(self.passwordNewTF);
        make.height.mas_equalTo(self).multipliedBy(.5);
    }];
    //
    UIView *sepOne = [self sepLine];
    [self addSubview:sepOne];
    UIView *sepTwo = [self sepLine];
    [self addSubview:sepTwo];
    [sepOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10.0);
        make.bottom.mas_equalTo(self.passwordNewTF);
        make.right.mas_equalTo(self);
        make.height.mas_equalTo(1.0);
    }];
    [sepTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(sepOne);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(sepOne);
    }];
}
- (UITextField *)passwordTextFeild {
    UITextField *tf = [UITextField new];
    tf.tintColor = GSLOGINRGBRGBHEX(0x000000);
    tf.font = [UIFont systemFontOfSize:19 weight:UIFontWeightRegular];
    tf.secureTextEntry = true;
    tf.inputAccessoryView = [UIView new];
    return tf;
}
- (UIView *)sepLine {
    UIView *sep = [UIView new];
    sep.backgroundColor = GSLOGINRGBRGBHEX(0xEDECEC);
    return sep;
}

#pragma mark - get
- (NSString *)password {
    return self.passwordNewTF.text;
}
- (NSString *)rePassword {
    return self.rePasswordNewTF.text;
}

#pragma mark - noti
- (void)passwordTextFeildDidChangedNotification {
    if (self.resetComplete) {
        self.resetComplete(self.password.length&&self.rePassword.length);
    }
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
